package com.sinopec.basemodule.base.basekt

import android.view.View
import androidx.annotation.CallSuper
import com.jakewharton.rxbinding3.view.clicks
import com.sinopec.basemodule.base.BaseActivity
import com.sinopec.basemodule.base.BasePresenter
import com.sinopec.basemodule.base.CustomToolbar
import io.reactivex.functions.Consumer
import java.util.concurrent.TimeUnit

/**
 * kt 版本的base
 */
abstract class BaseActivityKt<T : BasePresenter>(
    private val layoutId: Int,
    private val title: String = ""
) : BaseActivity<T>() {
    override fun getContentView(): Int {
        return layoutId
    }

    @CallSuper
    override fun configToolbar(rToolbar: CustomToolbar?) {
        rToolbar?.setTitle(title)
    }

    fun View.click(clickListener: (View) -> Unit) {
        addDisposable(
            clicks()
                .throttleFirst(1, TimeUnit.SECONDS)
                .subscribe(Consumer<Unit> { clickListener(this) })
        )
    }

}
